package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /*
     * 统计符合条件数据数量
     * */
    Long select(String name,Integer type);

    /*
     * 获取分类页面数据
     * */
    List<Category> selectPage(String name,Integer type ,Integer index, Integer pageSize);

    /*
     * 新增分类
     * */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into category (type, name, sort, status, create_time, update_time, create_user, update_user) " +
            "VALUES (#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Category category);

    /*
    * 修改分类信息
    * */
    @AutoFill(value = OperationType.UPDATE)
    void update(Category category);

    /*
    * 根据id删除分类
    * */
    @Delete("delete from category where id=#{id}")
    void deleteById(Long id);

    @Select("select * from category where type=#{type} and status=1 order by sort ,create_time desc")
    List<Category> selectByType(Integer type);

    /*
    * 查询数据
    * */
    List<Category> selectCategory(Category category);
}
